package com.learner.ucenter.controller.api;

import com.learner.pojo.user.FeedBack;
import com.learner.pojo.user.SensitiveMessage;
import com.learner.pojo.user.User;
import com.learner.pojo.user.vo.FeedBackResultVo;
import com.learner.pojo.user.vo.SensitiveMessageResultVo;
import com.learner.ucenter.filter.SensitiveFilter;
import com.learner.ucenter.service.OnlineUserService;
import com.learner.ucenter.service.UserService;
import com.learner.ucenter.utils.SystemUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ice2020x
 * @Date: 2023/2/27
 * @Description: 系统模块控制器
 **/
@RequestMapping("/api/ucenter/system")
@RestController
@Slf4j
public class SystemController {

    @Autowired
    private UserService userService;

    @Autowired
    private OnlineUserService onlineUserService;

    @Autowired
    private SensitiveFilter sensitiveFilter;




    /**
     * 获取系统CPU、内存使用率
     *
     * @return 系统CPU、内存使用率
     */
    @GetMapping("/sysSituation")
    @ResponseBody
    public Map<String, Object> getSysInfo() {
        double cpuUsage = SystemUtil.getSystemCpuLoad();
        double memUsage = SystemUtil.getSystemMemLoad();
        Map<String, Object> result = new HashMap<>(2);
        result.put("cpuUsage", cpuUsage);
        result.put("memUsage", memUsage);
        return result;
    }

    /**
     * 获取所有用户
     *
     * @return 请求结果
     */
    @GetMapping("/getAllUser")
    @ResponseBody
    public List<User> getAllUser() {
        return userService.getUserList();
    }

    /**
     * 根据注册时间获取用户
     *
     * @param lt 时间
     * @param rt 时间
     * @return 请求结果
     */
    @GetMapping("/getUsersBySignUpTime")
    @ResponseBody
    public List<User> getUsersBySignUpTime(String lt, String rt) {
        return userService.getUsersBySignUpTime(lt, rt);
    }

    /**
     * 获取当前在线用户的个数
     *
     */
    @GetMapping("/countOnlineUser")
    @ResponseBody
    public int getOnlineUserNums() {
        return onlineUserService.countOnlineUser();
    }

    /**
     * 更改用户状态
     *
     * @param uid    用户id
     * @param status 状态
     */
    @GetMapping("/changeUserStatus")
    @ResponseBody
    public void changeUserStatus(String uid, Integer status) {
        userService.changeUserStatus(uid, status);
    }




}
